import ctypes

# 相关文档
# ARM解决方案
# 「页面」apk逆向之so库的破解和调用小知识，大挑战！本文正在参与“ 程序员必备小知识  ”创作活动 so库调用方式尝试 1. - 掘金  https://juejin.cn/post/7020960328733163527
# 「页面」【教程】python使用 ExAndroidNativeEmu 调用安卓 so 库，并使用 nuitka 打包为 exe 过程记录 · nilaoda/Blog · Discussion #73  https://github.com/nilaoda/Blog/discussions/73
# 「页面」跨平台模拟执行- AndroidNativeEmu食用手册 - 『移动安全区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn  https://www.52pojie.cn/thread-1031123-1-1.html

lib = ctypes.CDLL('libkmsec.so')


lib.decrypt.argtypes = [ctypes.c_char_p]
lib.decrypt.restype = ctypes.c_char_p

lib.encrypt.argtypes = [ctypes.c_char_p]
lib.encrypt.restype = ctypes.c_char_p

lib.native_checkRisk.argtypes = []
lib.native_checkRisk.restype = ctypes.c_bool

lib.sign.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
lib.sign.restype = ctypes.c_char_p


def init():
    try:
        
        lib = ctypes.CDLL('libkmsec.so')
        print("Library loaded successfully")
    except Exception as e:
        print(f"Failed to load library: {e}")
        return False
    return True


if init():
    try:
        encrypted = lib.encrypt(b"test_string")
        decrypted = lib.decrypt(encrypted)
        risk_checked = lib.native_checkRisk()
        signed = lib.sign(b"string1", b"string2", b"string3")

        print(f"Encrypted: {encrypted.decode('utf-8')}")
        print(f"Decrypted: {decrypted.decode('utf-8')}")
        print(f"Risk Checked: {risk_checked}")
        print(f"Signed: {signed.decode('utf-8')}")
    except Exception as e:
        print(f"Error calling native methods: {e}")